package com.lr.wfxmanager.merchant.service.impl;

import com.lr.wfxmanager.merchant.bean.WxbCustomer;
import com.lr.wfxmanager.merchant.mapper.MerchantMapper;
import com.lr.wfxmanager.merchant.service.IMerchantService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;
import java.util.Random;

@Service
public class MerchantServiceImpl implements IMerchantService {
    @Resource
    private MerchantMapper merchantMapper;
    @Override
    public List<WxbCustomer> queryMerchantList() {
        return merchantMapper.queryMerchantList();
    }

    @Override
    public void addMerchant(WxbCustomer wxbCustomer){
        Random random = new Random();
        int id = random.nextInt(100000);
        /*设置id*/
        wxbCustomer.setCustomerId("lr"+id);
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        /*当前创建时间*/
        wxbCustomer.setCreatetime(timestamp);
        /*密码加密*/
        Md5Hash md5Hash = new Md5Hash(wxbCustomer.getLoginPwd());
        String hex = md5Hash.toHex();
        wxbCustomer.setLoginPwd(hex);
        System.out.println(wxbCustomer);
        merchantMapper.addMerchant(wxbCustomer);
    }
}
